package com.hns.can.service.service;

import com.hns.can.service.vo.DriverRankVo;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 司机总评分service
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class DriverRankService extends CommonService {

    @Autowired
    private FillCodeDscValue codeDscValue;

    private void fillCodeDscValue(List list)throws Exception{
        Map<String,String> map = new HashMap<String,String>();
        map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo1 = new FillParamsVo("organId", map);
        map = new HashMap<String,String>();
        map.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo2 = new FillParamsVo("drvId", map);
        map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo3 = new FillParamsVo("lineId", map);
        codeDscValue.fillInfoValue(list,new String[]{GlobalConst.CACHE_KEY_BASE_ORGAN,GlobalConst.CACHE_KEY_BASE_DRV_INFO,GlobalConst.CACHE_KEY_BASE_LINE_INFO},vo1,vo2,vo3);
    }


    /**
     * 分页查询司机总评分
     * @param vo
     * @author:zhangzq
     * @email:
     */
    @LeftOrgAnnotation()
    @Transactional
    public Pagination searchDriverRank(CommonParamsVo vo) throws Exception {
        Pagination page = this.myBatisPage("driverRank.getDriverRankCount", "driverRank.getDriverRankData", vo, DriverRankVo.class);
        List<Object> list = page.getData();
        fillCodeDscValue(list);
        page.setData(list);
        return page;
    }

    /**
     * 查询司机总评分用于导出文档
     * @param vo
     * @author:zhangzq
     * @email:
     */
    @SuppressWarnings("unchecked")
    @LeftOrgAnnotation()
    @Transactional
    public List<DriverRankVo> getAllDriverRank(CommonParamsVo vo) throws Exception {
        List<DriverRankVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("driverRank.getDriverRankData", vo), DriverRankVo.class);
        fillCodeDscValue(list);
        return list;
    }
}
